package com.u.finance.loans.service.impl;

import com.u.finance.loans.entity.User;
import com.u.finance.loans.mapper.UserMapper;
import com.u.finance.loans.model.FaceRecognitionDTO;
import com.u.finance.loans.service.IUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Alex Wu
 * @since 2025-03-28
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {
    @Override
    public FaceRecognitionDTO checkRealUser(String userId, MultipartFile picFrame) {
        User user = this.getById(userId);
        System.out.println("根据 User信息 与 PicFrame 进行人脸识别，返回识别结果");

        FaceRecognitionDTO faceRecognitionDTO = new FaceRecognitionDTO();
        for (int i = 0; i < 10; i++) {
            System.out.println("模拟人脸识别中...");
            faceRecognitionDTO.setStatus(1);

            if(i == 9){
                faceRecognitionDTO.setStatus(2);
                String encryptCertificate = encryptCertificate("12345");
                faceRecognitionDTO.setCertificate(encryptCertificate);
            }
        }
        return faceRecognitionDTO;
    }

    private String encryptCertificate(String certificate) {
        return "encrypted_" + certificate;
    }

    @Override
    public String decodeCertificate(String certificate) {
        return "decode_" + certificate;
    }
}
